package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.cart.CartFeignClient;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mqx
 * @date 2020-10-20 15:40:10
 */
@Controller
public class CartController {

    @Autowired
    private CartFeignClient cartFeignClient;

    @Autowired
    private ProductFeignClient productFeignClient;

    //  查询购物车列表 ，只需要编写一个映射器！

    @RequestMapping("cart.html")
    public String cartList(){

        return "cart/index";
    }

    //  addCart.html?skuId=126&skuNum=1
    @RequestMapping("addCart.html")
    public String addCart(Long skuId,
                          Integer skuNum,
                          HttpServletRequest request){
        System.out.println(skuId+":\t");
        System.out.println(skuNum+":\t");

        //  调用方法，没有返回值
        cartFeignClient.addToCart(skuId,skuNum);
        //  页面渲染需要
        request.setAttribute("skuNum",skuNum);
        request.setAttribute("skuInfo",productFeignClient.getSkuInfo(skuId));

        return "cart/addCart";
    }
}
